package com.xiaofang.serivce.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaofang.mapper.TitleMapper;
import com.xiaofang.pojo.Title;
import com.xiaofang.pojo.dto.TitleDto;
import com.xiaofang.serivce.TitleSerivce;
import com.xiaofang.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @program: xiaofangbackend
 * @ClassName TitleSerivceImpl
 * @description:
 * @author: aodi
 * @create: 2025-06-20 18:54
 * @Version 1.0
 */
@Service
public class TitleSerivceImpl   implements TitleSerivce {

    @Autowired
    private TitleMapper titleMapper ;


//    多条件查询
    @Override
    @Transactional(propagation = Propagation.REQUIRED ,readOnly = true)
    public  Page getTitle(TitleDto title) {


        if (title.getTitleTitle() != null && !"".equals(title.getTitleTitle())){
            String[] split = title.getTitleTitle().split("\\s|\\\\");
            title.setTitleTitleArr(split);
        }
        PageHelper.startPage(title.getPageNum(),title.getPageSize());
        List<Title> titles = titleMapper.getTitle(title);
        PageInfo<Title> titlePageInfo = new PageInfo<>(titles);


        return   new Page<Title>(titlePageInfo.getPageNum()
                ,titlePageInfo.getPageSize(),
                titlePageInfo.getPages(),titlePageInfo.getTotal(),titles);
    }
}
